package com.example.demo.controller;

import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/create")
    public String showRegisterPage() {
        return "user/create";
    }

    @PostMapping("/create")
    public String registerUser(@RequestParam String username, @RequestParam String password) {
        userService.createUser(username, password); // 保存到数据库
        System.out.println(username);
        return "redirect:/login"; // 重定向到登录页面
    }
}